@echo off
chcp 65001 > nul
echo.

echo ----------------------------------------
echo   OpenSSL 证书生成脚本 (自动填写信息)
echo ----------------------------------------
echo.

set "COMMON_NAME=YourCompany.com"
set "ORG_NAME=Your Company LLC"
set "ORG_UNIT=IT Department"
set "LOCALITY=YourCity"
set "STATE=YourState"
set "COUNTRY=CN"
set "EMAIL_ADDRESS=admin@yourcompany.com"

echo 1. 生成私钥和 CSR (request.csr) ...
openssl req -newkey rsa:2048 -nodes -keyout private.key -out request.csr -subj "/C=%COUNTRY%/ST=%STATE%/L=%LOCALITY%/O=%ORG_NAME%/OU=%ORG_UNIT%/CN=%COMMON_NAME%/emailAddress=%EMAIL_ADDRESS%"
echo 私钥 (private.key) 和 CSR (request.csr) 已生成。
echo.

echo 2. 生成自签名证书 (certificate.crt) ...
openssl x509 -req -days 36500 -in request.csr -signkey private.key -out certificate.crt
echo 自签名证书 (certificate.crt) 已生成，有效期100年。
echo.

echo 3. 生成 .pfx 文件 (certificate.pfx) ...
openssl pkcs12 -export -out certificate.pfx -inkey private.key -in certificate.crt -passout pass:youcertificatepassword
echo .pfx 文件 (certificate.pfx) 已生成。
echo.

echo ----------------------------------------
echo   所有操作已完成。
echo ----------------------------------------
pause